Auto merge of #4060 - alexcrichton:nobare, r=matklad
authorbors <bors@rust-lang.org>
Wed, 17 May 2017 01:33:51 +0000 (01:33 +0000)
committerbors <bors@rust-lang.org>
Wed, 17 May 2017 01:33:51 +0000 (01:33 +0000)
Don't use a bare checkout of the index

Both old and new Cargo share the same index, so be sure to maintain
compatibility by initializing a non-bare repository for the index. Note that
a nightly Cargo still won't check out the index, but when an older Cargo comes
along and tries to check it out then it'll work.

Closes #4058

1  2 
src/cargo/sources/registry/remote.rs

index 4852bf1d731271d797e58c4afaea6537566a0d6e,eb1d03168a519e400a8b5d0de9ebbe759e941d4e..cac0c7a8be327ec90ffca6ef850c775b8e897766
@@@ -67,8 -58,24 +67,20 @@@ impl<'cfg> RemoteRegistry<'cfg> 
              match git2::Repository::open(&path) {
                  Ok(repo) => Ok(repo),
                  Err(_) => {
 -                    self.index_path.create_dir()?;
 -                    let lock = self.index_path.open_rw(Path::new(INDEX_LOCK),
 -                                                       self.config,
 -                                                       "the registry index")?;
                      let _ = lock.remove_siblings();
-                     Ok(git2::Repository::init_bare(&path)?)
+                     // Note that we'd actually prefer to use a bare repository
+                     // here as we're not actually going to check anything out.
+                     // All versions of Cargo, though, share the same CARGO_HOME,
+                     // so for compatibility with older Cargo which *does* do
+                     // checkouts we make sure to initialize a new full
+                     // repository (not a bare one).
+                     //
+                     // We should change this to `init_bare` whenever we feel
+                     // like enough time has passed or if we change the directory
+                     // that the folder is located in, such as by changing the
+                     // hash at the end of the directory.
+                     Ok(git2::Repository::init(&path)?)
                  }
              }
          })